<template>
  <div class='xtx-goods-page'>
    <!-- 判定是否 拿到数据  拿到数据 再渲染 否则 会报错 -->
    <div class="container" v-if="goods && goods.categories && goods.categories.length > 0">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/category/${goods.categories[1].id}`">
          {{ goods.categories[1].name }}
        </XtxBreadItem>
        <XtxBreadItem :to="`/category/sub/${goods.categories[0].id}`">
          {{ goods.categories[0].name }}
        </XtxBreadItem>
        <XtxBreadItem>
          {{ goods.name }}
        </XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <!-- <div class="goods-info"></div> -->
         <!-- 商品信息 -->
      <div class="goods-info">
        <!-- 图片预览区 -->
        <div class="media">
          <!-- 图片预览区 -->
          <XtxImageView :imageList="goods.mainPictures"></XtxImageView>
          <!-- 统计数量 -->
          <GoodsSale :goods="goods"></GoodsSale>
        </div>
        <!-- 商品信息区 -->
        <div class="spec">
          <!-- 商品信息区 -->
          <GoodsInfo :goods="goods"></GoodsInfo>
        </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { reqFindGoods } from '@/api/goods'
import { provide, ref } from 'vue'
import GoodsSale from './components/goods-sale.vue'
import GoodsInfo from './components/goods-info.vue'
import { useRoute } from 'vue-router'
export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsSale,
    GoodsInfo
  },
  setup () {
    const goods = ref({})
    provide('separator', '>')
    const route = useRoute()
    async function getGoods () {
      // v2  this.$route.params.id
      const res = await reqFindGoods(route.params.id)
      console.log(res, 66)
      goods.value = res.result
    }
    getGoods()
    return { goods }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
}

.goods-footer {
  display: flex;
  margin-top: 20px;

  .goods-article {
    width: 940px;
    margin-right: 20px;
  }

  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}

.goods-tabs {
  min-height: 600px;
  background: #fff;
}

.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;

  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }

  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
</style>
